package com.h.aop.proxy;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class Main {
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();
//        HouseSubject houseSubject = new HouseProxy(target);
////        houseSubject.saleHouse();
//        houseSubject.rentHouse();

        // JDK动态代理
        // 动态创建一个代理类
//        HouseSubject houseProxy = (HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
//                new Class[]{HouseSubject.class}, new JDKInvocation(target));
//        houseProxy.rentHouse();

        //Cglib 动态代理
        HouseSubject houseProxy = (HouseSubject) Enhancer.create(target.getClass(), new CGlibMethodInterceptor(target));
        houseProxy.rentHouse();
    }
}
